<?php

//print_r($_POST);
 
// username and password sent from form 
$Orid=$_POST['id']; 
$uid=$_POST['uid'];
if(isset($_POST['number'])&&is_numeric($_POST['number'])){
$number=$_POST['number'];
}else{
 header("location:../index.php?page=organization_return&id=".$Orid."&stat=error&error=badData");
	
}

if(isset($_POST['amount'])&&is_numeric($_POST['amount'])){
$amount=$_POST['amount'];
}else{
 header("location:../index.php?page=organization_return&id=".$Orid."&stat=error&error=badData");
	
}

$val=$_POST['val'];



if($val=='unit'){
	$amount=$amount*$number;
}

    $scan_code=$_POST['scan_code'];
	if(strlen($scan_code)!=14){
		header("location:../index.php?page=organization_return&id=".$Orid."&stat=error&error=badData");
		
	}

    if(isItemExist($scan_code,$designer)){
    	//addItem($Orid,$scan_code,$uid,$number);
		//return;
    	if(returnItem($Orid,$scan_code,$uid,$number,$amount)){
    		
    		 header("location:../index.php?page=organization_return&id=".$Orid."&stat=returned");
			
    	}else{
        	  header("location:../index.php?page=organization_return&id=".$Orid."&stat=error&error=badData");
			
    	}
    }else{
        	  header("location:../index.php?page=organization_return&id=".$Orid."&stat=error&error=notExist");

		
    }
	
	echo "is_numeric";


?>